<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> - 基本表单</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="../favicon.ico">
    <link href="/Public/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/Public/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/Public/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/Public/css/animate.css" rel="stylesheet">
    <link href="/Public/css/style.css?v=4.1.0" rel="stylesheet">

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" onsubmit="return false">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">*选择客服公司</label>
                            <div class="col-sm-10">
                                <select name="rid" id="first" onchange="change()">
                                    <volist name="data" id="vo">
                                        <option value="<{$vo.kf_company_id}>"><{$vo.kf_company_name}></option>
                                    </volist>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">选择客服人员</label>
                            <div class="col-sm-10" >
                                <select name="rid" id="second">
                                    <!--<volist name="role" id="vo">-->
                                        <!--<option><{$vo.name}></option>-->
                                    <!--</volist>-->
                                </select>
                                <!--<span style="display: inline-block;color: #b81900">为空则表示派发给外包公司主管</span>-->
                            </div>

                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">

                                <button class="btn btn-primary" type="button" onclick="send()">确认分配</button>

                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/Public/js/jquery.min.js?v=2.1.4"></script>
<script src="/Public/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/Public/js/content.js?v=1.0.0"></script>
<script src="/Public/js/plugins/layer/layer.min.js"></script>

<script src="/Public/admin/js/layer/layer.js"></script>
<script src="/Public/admin/js/layui/layui.js"></script>
<script>


    var second6 = document.getElementById("second");
    second6.options.add(new Option("", "0", false, true));  // 默认选中
       var first6 = document.getElementById("first");
    first6.options.add(new Option("", "0", false, true));  // 默认选中


    //公司选中后 刷新人员
    function change() {
        var first = document.getElementById("first");
        second.options.length = 0;//清掉二级数据
        var index1 = first.selectedIndex;
        var index = first.options[index1].value;
        var url = "<{$SRVER_NAME}>/admin.php/OutboundManerger/get_second";
        $.post(url, {id: index}, function (data) {
            if (data.code == "1001") {
                console.log('11111', data.result);
                second.options.add(new Option("", "0", false, true));  // 默认选中

                for (var i = 0; i < data.result.length; i++) {
                    second.options.add(new Option(data.result[i].name, data.result[i].kf_id));
                }
            }
            else {
                second.options.add(new Option("", "0", false, true));  // 默认选中
            }
        });
    }


    function send() {
        var index = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        var url = "<{$SRVER_NAME}>/admin.php/OutboundManerger/send_add";
        var txt = "<{$txt}>";
        var url_type = "<{$url_type}>";

        var first = document.getElementById("first");
        var second = document.getElementById("second");
        var first_index = first.selectedIndex;
        var first_index1 = first.options[first_index].value;
        var second_index = second.selectedIndex;
        var second_index1 = second.options[second_index].value;
//        console.log('12312',first_index1);
//        return false;
        if ( first_index1=='0') {
            layer.close(index);
            layer.alert("请选择外包公司！\r\n", {
                title: '提示框',
                icon: 0,
            });
            return false;
        }
        if ( second_index1=='0') {
            layer.close(index);
            layer.alert("请选择分配客服！\r\n", {
                title: '提示框',
                icon: 0,
            });
            return false;
        }
        $.post(url, {send_string: txt, url_type: url_type,first:first_index1,second:second_index1}, function (data) {
            if (data.code == "1001") {

                layer.alert('派发成功', {title: '提示框', icon: 1}, function () {
                    var index1 = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index1);
                    parent.location.reload();

                });
            }
            else {
                layer.alert('派发 失败', {title: '提示框', icon: 1});

            }
        });
        layer.close(index);
    }


</script>
</body>
</html>
